# coding=utf-8
# 比较三只股票的夏普比率

import data.stock as dt
import strategy.base as stb
import pandas as pd
import matplotlib.pyplot as plt

codes = ['002088.XSHE', '600141.XSHG', '601677.XSHG']

sharpes = []
# 计算三只股票的夏普比率
for code in codes:
    data = dt.get_single_stock(code, '2019-01-01', '2019-06-01', per_fre='daily')
    daily_rate, year_rate = stb.calculate_sharpe_rate(data)
    # 组装成dataframe
    sharpes.append([code, year_rate])

# 将sharpes 转换成dataframe,以code为index
sp_df = pd.DataFrame(sharpes, columns=['code', 'year_rate']).set_index('code')
# 数据可视化,绘制柱状图
sp_df.plot.bar()
# 设置x轴为横向
plt.xticks(rotation=0)
plt.show()

